﻿using JSLCloud.Models;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;

namespace JSLCloud.Utilities.WebApi
{
    public static class HttpHelper
    {
        //private static object addModel;

        ///// <summary>
        ///// Get Request
        ///// </summary>
        ///// <typeparam name="T">返回结果类型</typeparam>
        ///// <typeparam name="T2">查询条件</typeparam>
        ///// <typeparam name="T3"></typeparam>
        ///// <param name="queryConditions"></param>
        ///// <param name="orderByConditions"></param>
        ///// <param name="url"></param>
        ///// <returns></returns>
        //public static T Get<T>(List<QueryCondition> queryConditions, List<OrderByCondition> orderByConditions, string url)
        //{
        //    var getModel = new RequestGet
        //    {
        //        QueryConditions = queryConditions,
        //        OrderByConditions = orderByConditions
        //    };
        //    var getModelJson = JsonConvert.SerializeObject(getModel);
        //    var resultJson = HttpRequestHelper.Get(url, getModelJson);
        //    var result = JsonConvert.DeserializeObject<ResponseObject<T>>(resultJson);
        //    if (result == null)
        //        return default;
        //    if (result.Code == -1)
        //        throw new Exception(result.Info);
        //    return result.Data;
        //}

        //public static T Get<T>(string strParam, string url)
        //{
        //    var resultJson = HttpRequestHelper.GetWithParams(url, strParam);
        //    var result = JsonConvert.DeserializeObject<ResponseObject<T>>(resultJson);
        //    if (result == null)
        //        return default;
        //    if (result.Code == -1)
        //        throw new Exception(result.Info);
        //    return result.Data;
        //}

        //public static T Post<T, T2>(T2 addModel, string url)
        //{
        //    var postModel = new RequestPost<T2>
        //    {
        //        PostData = addModel
        //    };
        //    var postModelJson = JsonConvert.SerializeObject(postModel);
        //    var resultJson = HttpRequestHelper.Post(url, postModelJson);
        //    var result = JsonConvert.DeserializeObject<ResponseObject<T>>(resultJson);
        //    if (result == null)
        //        return default;
        //    if (result.Code == -1)
        //        throw new Exception(result.Info);
        //    return result.Data;
        //}

        //public static T PostList<T, T2>(List<T2> addModelList, string url)
        //{
        //    var postModel = new RequestPost<T2>
        //    {
        //        PostDataList = addModelList
        //    };
        //    var postModelJson = JsonConvert.SerializeObject(postModel);
        //    var resultJson = HttpRequestHelper.Post(url, postModelJson);
        //    var result = JsonConvert.DeserializeObject<ResponseObject<T>>(resultJson);
        //    if (result == null)
        //        return default;
        //    if (result.Code == -1)
        //        throw new Exception(result.Info);
        //    return result.Data;
        //}

        //public static T Put<T, T2>(T2 editModel, string url)
        //{
        //    var putModel = new RequestPut<T2>
        //    {
        //        PostData = editModel
        //    };
        //    var putModelJson = JsonConvert.SerializeObject(putModel);
        //    var resultJson = HttpRequestHelper.Put(url, putModelJson);
        //    var result = JsonConvert.DeserializeObject<ResponseObject<T>>(resultJson);
        //    if (result == null)
        //        return default;
        //    if (result.Code == -1)
        //        throw new Exception(result.Info);
        //    return result.Data;
        //}

        //public static T PutList<T, T2>(List<T2> editModelList, string url)
        //{
        //    var putModel = new RequestPut<T2>
        //    {
        //        PostDataList = editModelList
        //    };
        //    var putModelJson = JsonConvert.SerializeObject(putModel);
        //    var resultJson = HttpRequestHelper.Put(url, putModelJson);
        //    var result = JsonConvert.DeserializeObject<ResponseObject<T>>(resultJson);
        //    if (result == null)
        //        return default;
        //    if (result.Code == -1)
        //        throw new Exception(result.Info);
        //    return result.Data;
        //}

        //public static T Delete<T, T2>(T2 deleteModel, string url)
        //{
        //    var postModel = new RequestPost<T2>
        //    {
        //        PostData = deleteModel
        //    };
        //    var postModelJson = JsonConvert.SerializeObject(postModel);
        //    var resultJson = HttpRequestHelper.Post(url, postModelJson);
        //    var result = JsonConvert.DeserializeObject<ResponseObject<T>>(resultJson);
        //    if (result == null)
        //        return default;
        //    if (result.Code == -1)
        //        throw new Exception(result.Info);
        //    return result.Data;
        //}
    }
}
